package com.game.code;

import org.jbox2d.callbacks.ContactImpulse;
import org.jbox2d.callbacks.ContactListener;
import org.jbox2d.collision.Manifold;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.World;
import org.jbox2d.dynamics.contacts.Contact;

public class CollisionsListener implements ContactListener{

	World world;
	
	public void beginContact(Contact point) {}

	public void endContact(Contact point) {
		Body b1=point.getFixtureA().getBody();
		Body b2=point.getFixtureA().getBody();

		if(b1.getUserData().equals("brick")){b1.setActive(false);}
		if(b2.getUserData().equals("brick")){b2.setActive(false);}
		
		if(Check(b1,b2,"ball","ground")){
			//end of game
			b1.setActive(false);
			b2.setActive(false);
		}
	}

	private boolean Check(Body b1,Body b2,String name1,String name2){
		boolean flag=false;
		if((b1.getUserData().equals(name1) && b1.getUserData().equals(name2))||
		   (b2.getUserData().equals(name1) && b2.getUserData().equals(name2))){
			flag=true;
		}
		return flag;
	}
	
	public void preSolve(Contact contact, Manifold oldManifold) {}

	public void postSolve(Contact contact, ContactImpulse impulse) {}

}
